package com.theme.passport.service.theme.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.utils.Query;
import com.theme.passport.dao.theme.WallpaperClassifyDao;
import com.theme.passport.entity.theme.WallpaperClassifyEntity;
import com.theme.passport.service.theme.WallpaperClassifyService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("wallpaperClassifyService")
public class WallpaperClassifyServiceImpl extends ServiceImpl<WallpaperClassifyDao, WallpaperClassifyEntity> implements WallpaperClassifyService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String keyword = (String) params.get("key");
        String parentId = (String) params.get("parentId");
        String isParent = (String) params.get("isParent");
        IPage<WallpaperClassifyEntity> page = this.page(
                new Query<WallpaperClassifyEntity>().getPage(params),
                new QueryWrapper<WallpaperClassifyEntity>()
                        .like(StringUtils.isNotBlank(keyword), "name", keyword)
                        .eq(StringUtils.isNotBlank(parentId), "parent_id", parentId)
                        .eq(StringUtils.isNotBlank(isParent), "is_parent", isParent)
                        .orderByAsc("sort_order")
        );

        return new PageUtils(page);
    }

}